/**
 * Created by Administrator on 2017/3/30 0030.
 */
var PageSee={
    create: function () {
        var page={}
        page.ui=new PIXI.DisplayObjectContainer();
        var bg=new PIXI.Graphics();
        bg.beginFill(0x0,1);
        bg.drawRect(0,0,740,1136);
        bg.endFill();

        var con_0=new PIXI.DisplayObjectContainer();
        page.ui.addChild(con_0);

        var wel_i2=Easy.CreateSprite('assets/images/wel_i2.png',366,563,0.5,0.5,1);
        con_0.addChild(wel_i2);
        var wel_i0=Easy.CreateSprite('assets/images/wel_i0.png',366,563,0.5,0.5,1);
        con_0.addChild(wel_i0);
        var wel_i1=Easy.CreateSprite('assets/images/wel_i1.png',366,563,0.5,0.5,1);
        con_0.addChild(wel_i1);


        var i0=new PIXI.Sprite(resource['assets/images/pSee_i0.png'].texture);
        i0.anchor.set(0.5);
        page.ui.addChild(i0);
        i0.x=369;
        i0.y=574;

        var i1=new PIXI.Sprite(resource['assets/images/pSee_i1.png'].texture);
        i1.anchor.set(0.5);
        page.ui.addChild(i1);
        i1.x=369;
        i1.y=574;

        var i2=new PIXI.Sprite(resource['assets/images/pSee_i2.png'].texture);
        i2.anchor.set(0.5);
        page.ui.addChild(i2);
        i2.x=369;
        i2.y=574;

        var t0=new PIXI.Sprite(resource['assets/images/wel_t0.png'].texture);
        t0.anchor.set(0.5);
        con_0.addChild(t0);
        t0.x=373;
        t0.y=564;
        var mask_0=new PIXI.Graphics();
        mask_0.beginFill(0,1);
        mask_0.drawCircle(0,0,255);
        mask_0.endFill();
        mask_0.x=t0.x;
        mask_0.y=t0.y;
        mask_0.scale.x=mask_0.scale.y=0;
        con_0.addChild(mask_0);
        t0.mask=mask_0;

        var logo=Easy.CreateSprite('assets/images/logo.png',370,565,0.5,0.5,0);
        page.ui.addChild(logo);


        page.In=function()
        {
            //t2.mask=
            mask_0.scale.x=mask_0.scale.y=0;
            TweenMax.to(mask_0.scale,4,{delay:1,x:1,y:1,ease:Back.easeOut});

            wel_i0.scale.x=wel_i0.scale.y=0;
            TweenMax.to(wel_i0.scale,1,{delay:0.2,x:1,y:1,ease:Back.easeOut});
            wel_i1.scale.x=wel_i1.scale.y=0;
            TweenMax.to(wel_i1.scale,1,{delay:0.4,x:1,y:1,ease:Back.easeOut});
            wel_i2.scale.x=2.5;
            wel_i2.alpha=0;
            TweenMax.to(wel_i2.scale,1,{delay:0.7,x:1,ease:Back.easeOut});
            TweenMax.to(wel_i2,1,{delay:0.7,alpha:1,ease:Linear.easeNone});

            setTimeout(function()
            {
                TweenMax.to(con_0,1,{alpha:0,ease:Back.easeIn});
                createCircle();

                logo.scale.x=0;
                logo.scale.y=0;
                TweenMax.to(logo.scale,1,{delay:0.7,x:0.6,y:0.6,ease:Back.easeOut});
                TweenMax.to(logo,1,{delay:0.7,alpha:1,ease:Back.easeOut});
            },3000)


            i0.scale.x=i0.scale.y=i0.alpha=0;
            i1.scale.x=i1.scale.y=i1.alpha=0;
            i2.scale.x=i2.scale.y=i2.alpha=0;
            i0.rotation=-Math.PI*2;
            i1.rotation=Math.PI*1;
            i2.rotation=Math.PI/2;
            TweenMax.to(i0,1.5,{delay:1.5+2.5,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i0.scale,1.5,{delay:1.5+2.5,  x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i0,5,{rotation:Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            TweenMax.to(i1,1.5,{delay:1.5+2.7,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i1.scale,1.5,{delay:1.5+2.7,x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i1,10,{rotation:-Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            TweenMax.to(i2,1.5,{delay:1.5+3.4,alpha:1,rotation:0,ease:Back.easeOut});
            TweenMax.to(i2.scale,1.5,{delay:1.5+2.9,x:1,y:1,ease:Back.easeOut,onComplete:function()
            {
                TweenMax.to(i2,15,{rotation:Math.PI*2,repeat:-1,ease:Linear.easeNone});
            }});

            setTimeout(function()
            {


                TweenMax.to(i0,1,{delay:0.8,alpha:0,ease:Back.easeIn});
                TweenMax.to(i0.scale,1,{delay:0.8,x:4,y:4,ease:Back.easeIn});

                TweenMax.to(i1,1,{delay:0.9,alpha:0,ease:Back.easeIn});
                TweenMax.to(i1.scale,1,{delay:0.9,x:4,y:4,ease:Back.easeIn});

                TweenMax.to(i2,1,{delay:1.0,alpha:0,ease:Back.easeIn});
                TweenMax.to(i2.scale,1,{delay:1.0,x:4,y:4,ease:Back.easeIn});


                TweenMax.to(logo.scale,1,{delay:1,x:2,y:2,ease:Back.easeIn});
                TweenMax.to(logo,1,{delay:1,alpha:0,ease:Back.easeIn});

                threeOut();
                //以下逻辑写在threeOut里
                // setTimeout(function () {
                //     var evt=new CustomEvent('Game_PageIn',{detail:'mc'})
                //     document.dispatchEvent(evt);
                // },3000)
            },8000);
        }

        function createCircle()
        {
            for(var i=0;i<20;i++)
            {
                var circle=Circle.create(0,0,0x877B5F);
                page.ui.addChild(circle.ui);

                circle.ui.x=369;
                circle.ui.y=575;

                //arr_circle.push(circle);

                circle.ui.scale.x=0;
                circle.ui.scale.y=0;
                TweenMax.to(circle.ui,1.25,{delay:0.1*i,alpha:0});
                TweenMax.to(circle.ui.scale,1.25,{delay:0.05*i,x:1-i*0.01,y:1-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
                    c.ui.parent.removeChild(c.ui);
                    c=null;
                    //arr_circle.splice(arr_circle.indexOf(c),1);
                    //console.log(arr_circle.length);
                }});

            }
        }


        return page;
    }
}